<template>
  <div>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="a"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="phone"
        type="text"
        name="b"
        label="手机"
        placeholder="手机"
        :rules="[{ pattern: /^1[3-9]\d{9}$/, message: '请填写正确的手机号' }]"
      />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">提交</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      username: "",
      phone: "",
    };
  },
  methods: {
    onSubmit(values) {
      console.log("submit", values);
      axios
        .post("https://api.zkeji.com/liuyan/add", {
          myname: values.a,
          mytel: values.b,
          mytime: new Date(),
          mytag: "2",
        })
        .then((res) => {
          console.log(res.data);
          if (res.data.code === 0) {
            this.$toast.success('提交成功');
            this.username = ""
            this.phone = ""
            this.$emit('myclose', false)
          }
        })
    },
  },
};
</script>

<style>
</style>